package ihm;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSpinner;
import javax.swing.JList;
import java.awt.Scrollbar;
import java.awt.List;
import java.awt.ScrollPane;
import java.util.Vector;

import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionListener;
import javax.swing.UIManager;

import dao.Dao_client;

import application.MenuPrincipal;

import metier.Proprietaire;
import java.awt.SystemColor;

public class FenetreSupClient extends JDialog implements ActionListener
{

	private final JPanel contentPanel = new JPanel();
	private JButton btnAnnuler;
	private JButton btnSupprimer;
	private Vector<Proprietaire> lesProprietaires = Dao_client.getLesProprietaires();
	private String[] nomProprietaire = new String[lesProprietaires.size()];
	private final JList list;
	private int rep;
	private JPanel panelBouton;

	public static void main(String[] args)
	{
		try
		{
			FenetreSupClient dialog = new FenetreSupClient();
			
			dialog.setVisible(true);
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}


	public FenetreSupClient()
	{
		setTitle("Supprimer un client");
		setBounds(700, 300, 534, 254);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setBackground(new Color(178, 200, 219));
		contentPanel.setLayout(new BorderLayout(0, 0));
		
		int i = 0;
		for(Proprietaire unProprietaire : lesProprietaires)
		{
			nomProprietaire[i] = unProprietaire.getInfos();
			i++;
		}
		
		
		 list = new JList(nomProprietaire);
		 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		 
		 contentPanel.add(new JScrollPane(list,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    	     ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS));
				
				panelBouton = new JPanel();
				
				contentPanel.add(panelBouton, BorderLayout.SOUTH);
				
				btnSupprimer = new JButton("Supprimer");
				btnSupprimer.addActionListener(this);
				btnSupprimer.setActionCommand("OK");
				getRootPane().setDefaultButton(btnSupprimer);
				btnAnnuler = new JButton("Annuler");
				btnAnnuler.addActionListener(this);
				btnAnnuler.setActionCommand("Cancel");

				panelBouton.add(btnSupprimer);
				panelBouton.add(btnAnnuler);
	}
	
	public void actionPerformed(ActionEvent evt) {
		if(evt.getSource() == this.btnAnnuler)
			dispose();
		
		if(evt.getSource() == this.btnSupprimer)
			this.rep = JOptionPane.showConfirmDialog(null, "Etes vous sur de vouloir supprimer ce client ?","Message",JOptionPane.YES_NO_OPTION);

		if (this.rep == JOptionPane.YES_OPTION)
			dispose();
		
	}
	
}
